#!/bin/bash
# Program:
#   Get local IP address
# History:
#   2014/03/28  Sunny First release
#
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

# Local Network Adapter
LocalNetworkAdapter='eth0'

# Find 'eth0' really exists
result=$(ifconfig | grep -i $LocalNetworkAdapter)

# cut :
#   -d: single character                    ex: -d':'
#   -f: integer , to choose which section   ex: -f2
#   -c: range for int(a) to int(b)          ex: -c 12-[20]

if [ "result" != "" ]; then
  LocalIP=$(ifconfig $LocalNetworkAdapter | grep -i 'inet addr:' \
    | cut -d':' -f2 | cut -d' ' -f1)
  echo "Local Network Adapter :    $LocalNetworkAdapter"
  echo "Local IP Address      :    $LocalIP"
else
  echo "Local Network Adapter is not \"$LocalNetworkAdapter\"."
fi
